#1
def capitalize_words(text):
    return ' '.join(word.capitalize() for word in text.split())

input_text = "auto school of witchcraft and wizardry"
output_text = capitalize_words(input_text)
print(output_text)
#2
input_str = "Hello World"
output_str = ""
for char in input_str:
    output_str += char * 2

print(output_str)

#3
input_str = "hello  world"
output_str = ""
current_word = ""
for char in input_str:
    if char.isspace():
        # 如果遇到空格，将当前单词反转后添加到输出字符串，再添加空格
        output_str += current_word[::-1] + char
        current_word = ""
    else:
        # 如果不是空格，将字符添加到当前单词
        current_word += char
# 处理最后一个单词
output_str += current_word[::-1]
print(output_str)
#4
# 输出 1 - 1000 按指定格式的数字
for i in range(1, 1001):
    print(f"{i:04d}", end="、")
# 去除最后一个多余的顿号
print("\b ")

#5
input_str = "Wingardium Leviosa Wingardium Leviosa Expelliarmus Leviosa Expelliarmus"
# 按空格分割字符串得到单词列表
words = input_str.split()
unique_words = []
# 遍历单词列表
for word in words:
    if word not in unique_words:
        unique_words.append(word)
# 将去重后的单词列表用空格连接成字符串
output_str = ' '.join(unique_words)
print(output_str)

#6
def remove_duplicates_except_last(lst):
    result = []
    for num in reversed(lst):
        if num not in result:
            result.append(num)
    result.reverse()
    return result

input_list = [3, 4, 4, 3, 6, 3]
output_list = remove_duplicates_except_last(input_list)
print(output_list)

#7
a = [1, 2, 2, 2, 3]
b = [2]
# 定义一个空列表，用于存储结果
new_list = []
# 遍历列表 a 中的每个元素
for num in a:
    # 如果当前元素不在列表 b 中
    if num not in b:
        # 将该元素添加到新列表中
        new_list.append(num)

print(new_list)


#8
a = [2, 3, 9]
# 从列表末尾开始遍历
for i in range(len(a) - 1, -1, -1):
    if a[i] < 9:
        a[i] += 1
        break
    a[i] = 0
# 如果所有位都是 9，在列表开头插入 1
if a[0] == 0:
    a.insert(0, 1)
print(a)

a = [4, 3, 2, 5]
for i in range(len(a) - 1, -1, -1):
    if a[i] < 9:
        a[i] += 1
        break
    a[i] = 0
if a[0] == 0:
    a.insert(0, 1)
print(a)


#9
nums = [1, 2, 3, 4, 5, 6, 7]
k = 3

# 处理 k 大于列表长度的情况
k = k % len(nums)

# 将列表分成两部分并重新组合
nums = nums[-k:] + nums[:-k]

print(nums)